package com.whlilong.jxc.view;

import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Table;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;

import com.whlilong.jxc.constants.IAppConstants;
import com.whlilong.jxc.sys.CacheImage;
import com.whlilong.jxc.sys.IImageKey;
import com.whlilong.jxc.util.ViewerChange;

/**查询统计视图
 * @author sjy
 *
 */
public class QueryStatisticView extends ViewPart implements ISelectionListener{

	private Button xsinfo;
	private Button xsthinfo;
	private Button sprk;
	private Button rkth;
	private Button xsph;
	private Button analysis;

	public QueryStatisticView() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public void createPartControl(Composite parent) {
		// TODO Auto-generated method stub
		createContents(parent);
		PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().addSelectionListener(this);
	}

	private void createContents(Composite parent) {
		// TODO Auto-generated method stub
		Composite composite = new Composite(parent, SWT.NONE);
		GridLayout layout = new GridLayout();
		layout.numColumns = 2;
		layout.marginTop = 10;
		layout.marginBottom = 10;
		layout.marginRight = 10;
		layout.marginLeft = 10;
		layout.makeColumnsEqualWidth = true;

		composite.setLayout(layout);
		composite.setBackgroundImage(CacheImage.getINSTANCE().getImage(
				IAppConstants.APPLICATION_ID, IImageKey.FUNCTIONS_BG));
		
		createButton(composite);
	}

	private void createButton(Composite composite) {
		// TODO Auto-generated method stub
		GridData gd = new GridData(GridData.CENTER);
		gd.horizontalIndent = 30;
		gd.verticalIndent = 20;
		gd.widthHint = 130;
		gd.heightHint = 50;
		

		xsinfo = new Button(composite, SWT.NONE);
		xsinfo.setImage(CacheImage.getINSTANCE().getImage(
				IAppConstants.APPLICATION_ID, IImageKey.ceshi));
		xsinfo.setText("销售信息查询");
		xsinfo.setToolTipText(xsinfo.getText());
		xsinfo.setLayoutData(gd);
		
		xsthinfo = new Button(composite, SWT.NONE);
		xsthinfo.setImage(CacheImage.getINSTANCE().getImage(
				IAppConstants.APPLICATION_ID, IImageKey.ceshi));
		xsthinfo.setText("销售退货查询");
		xsthinfo.setToolTipText(xsthinfo.getText());
		xsthinfo.setLayoutData(gd);
		
		sprk = new Button(composite, SWT.NONE);
		sprk.setImage(CacheImage.getINSTANCE().getImage(
				IAppConstants.APPLICATION_ID, IImageKey.ceshi));
		sprk.setText("商品入库查询");
		sprk.setToolTipText(sprk.getText());
		sprk.setLayoutData(gd);
		
		rkth = new Button(composite, SWT.NONE);
		rkth.setImage(CacheImage.getINSTANCE().getImage(
				IAppConstants.APPLICATION_ID, IImageKey.ceshi));
		rkth.setText("入库退货查询");
		rkth.setToolTipText(rkth.getText());
		rkth.setLayoutData(gd);
		
		xsph = new Button(composite, SWT.NONE);
		xsph.setImage(CacheImage.getINSTANCE().getImage(
				IAppConstants.APPLICATION_ID, IImageKey.ceshi));
		xsph.setText("商品销售排行");
		xsph.setToolTipText(xsph.getText());
		xsph.setLayoutData(gd);
		
		analysis = new Button(composite, SWT.NONE);
		analysis.setImage(CacheImage.getINSTANCE().getImage(
				IAppConstants.APPLICATION_ID, IImageKey.ceshi));
		analysis.setText("年销售额分析");
		analysis.setToolTipText(analysis.getText());
		analysis.setLayoutData(gd);
	}

	@Override
	public void setFocus() {
		// TODO Auto-generated method stub

	}

	@Override
	public void selectionChanged(IWorkbenchPart part, ISelection selection) {
		if (!selection.isEmpty()) {
			IViewPart vp = getViewSite().getPage().findView(
					IAppConstants.systemManagerview_id);

			Table table = ((SystemManagerView) vp).getTableViewer().getTable();
			ViewerChange.getInstance().refreshView(table);
		}		
	}

}
